Skip to content

feat(compono-logging): host-wide log capture via LogCollector (#164) - #177

Merged
ncipollina merged 6 commits into
mainfrom
feat/164-host-wide-log-capture
Nov 11, 2026
Merged

ncipollina merged 6 commits into
mainfrom
feat/164-host-wide-log-capture

Conversation

@ncipollina

@ncipollina ncipollina commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements #164 (ADR-0071, ADR-0055 Amendment 6, PLAN-0072 B2-B7): a host-based test can now capture entries from every logger the host creates and verify them with the existing Compono vocabulary.

  • LogCollector (test-owned) + AddComponoCapture register an internal ILoggerProvider on the host's logging pipeline. Registration is idempotent per collector instance; two distinct collectors each receive every entry.
  • CapturedLogEntry.Category is added, with MEL-parity naming for composed CapturingLogger<T> and "" for non-generic loggers. Category participates in record equality — an intentional, documented behavioral change (not source/binary breaking).
  • AtLevelOrAbove and InCategory extend LogVerificationBuilder; both work on composed and host collectors.
  • Composed and host capture stay separate destinations in v1; host ILogger<T>.Verify() throws with guidance to use the collector.
  • Host filtering remains authoritative; default Information minimum means Debug/Trace need SetMinimumLevel. The [ProviderAlias("Compono")] alias works on every supported target framework (net8.0–net11.0) — see ADR-0071 Amendment 2 and the remediation section below.
  • Disposal stops capture through that host while pre-disposal entries stay readable; held loggers become non-capturing and BeginScope stays usable.

Validation

  • dotnet build Compono.slnx -c Release: 0 warnings / 0 errors.
  • dotnet test Compono.slnx -c Release --no-build: 7091 total, 0 failed, 6590 succeeded, 501 skipped.
  • test/Compono.Logging.Tests: 548 passed / 0 failed across net8/9/10/11.
  • Native AOT logging leg: pack + PublishAot net10.0/osx-arm64 passed (host capture + category parity + provider-alias rule), zero IL2xxx/IL3xxx warnings; packaging verification passed.
  • ApiCompat against 1.4.0-preview.125: additions only, 0 CP errors; packed nuspec dependency groups identical to baseline.
  • API reference regenerated; no unintended drift.
  • Skill evals.json parses (65 evals) and quick_validate.py passes.

Review remediation (independent review round)

A second review raised seven findings. Dispositions:

  • F1 — registration defect (fixed). AddComponoCapture → ClearProviders() → AddComponoCapture with the same collector silently stopped capturing, because duplicate detection used a separate marker descriptor that ClearProviders() leaves behind. Detection now inspects the live ILoggerProvider descriptor whose factory target is the registration. Regression tests: ClearProvidersThenReRegisteringTheSameCollector_StillCaptures, ClearProvidersThenReRegisteringTwice_StaysIdempotent, ClearProvidersThenRegisteringADifferentCollector_OnlyTheNewCollectorCaptures, SameCollectorOnIndependentServiceCollections_IsNotTreatedAsADuplicate.
  • F2 — provider alias on net8/net9 (fixed, ADR-0071 Amendment 2). The original PR applied [ProviderAlias("Compono")] only for net10.0+, so Logging:Compono:* rules silently did nothing on net8/net9. The attribute is now applied unconditionally; an internal same-full-name ProviderAliasAttribute copy is compiled on the older TFMs (MEL resolves aliases by full type name, so the copy is honored). No new package dependencies; CS0436 is promoted to an error so a collision can never be silent.
  • F3/F4/F5/F6 — documentation corrections. InCategory is exact ordinal full-type-name matching (not AddFilter-style prefix); Never() names filters and match count but does not list matching entries; a shared WebApplicationFactory retains entries until explicitly cleared; a replaced third-party ILoggerFactory (or a post-registration ClearProviders()) can yield an empty capture. Docs, how-to, troubleshooting, skill reference, and evals updated.
  • F7 — deferred. AOT warnings are not universally promoted to errors repo-wide; a pre-existing policy gap, not specific to this PR, and left out of scope.

Remediation validation

  • Full build 0/0; full suite 7087 total / 0 failed / 6586 succeeded / 501 skipped (round 1; 7091/0 after round 2).
  • Provider alias across TFMs (pack-and-consume): a multi-target (net8.0;net9.0;net10.0;net11.0) consumer restored Compono.Logging from a local feed packed from this branch (sha512-verified, not a stale nuget.org 1.0.0) builds 0 warnings/0 errors with CS0436/CS0104 treated as errors, and runs on every TFM. Logging:Compono:LogLevel:Default filters the Compono provider, an unrelated provider is unaffected, and a consumer-defined ProviderAliasAttribute use compiles unambiguously.
  • AOT for net8.0/net9.0 (CI only publishes net10.0): PublishAot osx-arm64 binaries built with zero IL2xxx/IL3xxx warnings and ran, honoring the alias. The net10.0 AOT leg and packaging verification also pass.
  • ApiCompat (1.4.0-preview.125 baseline) clean (additions only); packed-nupkg inspection and dependency-group equality pass.
  • API reference has no drift; evals.json parses (64 evals at round 1); skill quick_validate.py reports valid.

Review round 2 (approved with non-blocking follow-ups)

Claude's second read-only review approved with two follow-ups, both addressed:

  • Capture sanity check is now host-aware. The docs had recommended
    logs.Verify().InCategory("Microsoft.Hosting.Lifetime").AtLeast(1) unconditionally. That only holds for a
    Generic Host on its default lifetime; under WebApplicationFactory/ASP.NET Core TestHost the host lifetime
    differs and a shared fixture may clear startup entries between tests, so it can fail even when capture is
    wired correctly. The recommendation now keeps the Microsoft.Hosting.Lifetime assertion for a Generic Host
    and, for WebApplicationFactory, asserts a deterministic application-owned entry emitted during the
    operation under test. Updated the how-to, package guide, troubleshooting entry, and skill reference;
    sharpened eval feat(skills): add official Compono agent skill pack #63 and added eval feat(xunitv3): add ComposeAttribute<TProfile, TConfig> for call-site profile configuration #65.
  • Keyed-provider registration regression. Added
    KeyedProviderDescriptorPresent_DoesNotBreakRegistrationOrCapture: a keyed ILoggerProvider registered
    before AddComponoCapture still captures and does not throw, verified on net8.0/net9.0/net10.0/net11.0.
    While proving it, found the IsAlreadyRegistered comment was inaccurate — a keyed descriptor's
    ImplementationFactory is null on supported runtimes (it is KeyedImplementationFactory that throws on
    a non-keyed descriptor), so the !IsKeyedService guard is defense in depth rather than a throw guard. The
    guard stays; the comment was corrected.

Round-2 validation: build 0/0; logging 548/0 across net8/9/10/11; full suite 7091 total / 0 failed / 6590
succeeded / 501 skipped; mkdocs build --clean --strict exit 0; API reference no drift; evals.json parses
(65 evals) and quick_validate.py reports valid. No package- or AOT-affecting change, so those gates were
not re-run.

Docs

Package guide host-wide section, new how-to, two troubleshooting entries, API reference, compono skill reference/SKILL/evals. PLAN-0072 updated with results, the review-remediation entry, and acceptance-criteria mapping.

Closes #164.

Add an opt-in ILoggerProvider capture path so a Generic Host test can
assert across every category the host logs, including categories the
test never composes.

- Add Category to CapturedLogEntry (intentional behavioral equality
  change) with MEL-parity naming for composed loggers.
- Share one entry-construction path between composed and host capture.
- Add LogCollector and AddComponoCapture with per-collector
  idempotent registration and host-owned disposal.
- Add AtLevelOrAbove and InCategory verification filters.
- Cover real Generic Host capture, cardinality, disposal, isolation,
  bounded concurrency, Native AOT, and ApiCompat.
- Record ADR-0071 Amendment 1 for ProviderAlias availability on
  net10.0+ only.
- Update package docs, how-to, troubleshooting, API reference, and
  the compono skill/evals.

Implements #164 (B2-B6, PLAN-0072).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T15:07:57.789480Z 52dc39e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the type: feat New feature label Nov 11, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c27597de53

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +30 to +31
if (IsAlreadyRegistered(builder.Services, collector))
return builder;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Re-register capture when its provider has been removed

If logging setup calls AddComponoCapture(logs), then ClearProviders(), then AddComponoCapture(logs) again, the second registration silently does nothing: ClearProviders() removes the ILoggerProvider descriptor but leaves the separate ComponoCaptureRegistration marker behind. The resulting host never captures any entries, so an Error-level Never() assertion can incorrectly pass even when errors are logged. Track the actual provider descriptor alongside the collector and verify that it is still registered before taking this early return; add a regression test covering this registration sequence.

Useful? React with 👍 / 👎.

…on every TFM

Address the independent review of PR #177 (issue #164):

- AddComponoCapture -> ClearProviders -> AddComponoCapture(same collector)
  silently stopped capturing. Duplicate detection no longer relies on a
  separate marker descriptor that ClearProviders() leaves behind; it now
  inspects the live ILoggerProvider descriptor whose factory target is the
  registration. Adds ClearProviders/re-registration regression tests.
- The Compono provider alias now works on net8.0/net9.0 too, not just
  net10.0+: an internal same-full-name ProviderAliasAttribute copy is
  compiled on the older TFMs (MEL resolves the alias by full type name),
  with CS0436 promoted to an error. No new package dependencies. Recorded
  as ADR-0071 Amendment 2.
- Fix host-wide capture docs: InCategory is exact full-type-name matching
  (not AddFilter-style prefix), Never() does not list matching entries, a
  shared WebApplicationFactory retains entries between tests, and a
  replaced ILoggerFactory can bypass registered providers.

Validation: full build 0/0; full suite 7087 total/0 failed/6586 succeeded/
501 skipped; ApiCompat and packed-nupkg inspection clean (additions only,
dependency groups unchanged); multi-TFM pack-and-consume of Compono.Logging
verifies the alias + filtering on net8.0/net9.0/net10.0/net11.0; net8.0 and
net9.0 AOT publishes emit zero IL warnings and honor the alias.
The capture sanity assertion must be host-aware: a Generic Host on its
default lifetime logs Microsoft.Hosting.Lifetime on StartAsync, but
WebApplicationFactory/TestHost uses a different host lifetime and a shared
fixture may clear startup entries between tests, so that assertion is
unreliable there. Recommend a deterministic application-owned entry for
WebApplicationFactory, and update the how-to, package guide,
troubleshooting entry, skill reference, and evals.

Add a keyed ILoggerProvider regression test proving AddComponoCapture still
captures and does not throw. While verifying, correct the IsAlreadyRegistered
comment: on supported runtimes a keyed descriptor's ImplementationFactory is
null rather than throwing, so the !IsKeyedService guard is defense in depth.
@ncipollina

Copy link
Copy Markdown
Contributor Author

@codex review

Please perform a comprehensive, independent review of the entire PR diff against main, not just the latest commit.

This PR introduces host-wide logging capture for Compono.Logging. It has undergone two independent Claude review rounds, with all actionable findings addressed.

Please focus on:

  • Provider registration: Idempotency, ClearProviders() behavior, keyed service descriptors, ownership, and disposal.
  • Provider alias compatibility: The internal ProviderAliasAttribute shim for .NET 8/9, configuration filtering, consumer compatibility, and Native AOT.
  • Logging correctness: Concurrency, scope propagation, category preservation, filtering, and source-generated logging.
  • Verification semantics: InCategory(), AtLevelOrAbove(), Never(), and potential false-positive assertions.
  • Public API: Backward compatibility, API consistency, and unnecessary complexity.
  • Tests: Regression coverage, meaningful assertions, and missing edge cases.
  • Documentation: Accuracy of host-specific examples, troubleshooting guidance, and skill instructions.

Prioritize actionable correctness defects, API design problems, and maintainability risks over stylistic preferences.

For each finding, provide a concrete failure scenario, relevant file and line, severity, and recommended correction.

Please do not make changes. This is a review-only request.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 52dc39e8d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ncipollina
ncipollina merged commit ab2f0f0 into main Nov 11, 2026
23 checks passed
@ncipollina
ncipollina deleted the feat/164-host-wide-log-capture branch November 11, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feat New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Host-wide log capture across all categories via Compono.Logging

1 participant